package com.ry.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class Connection {
	
	
	/*String httpUrl = "http://www.rongyitech.com:6060";
		public void get() {
			String url = httpUrl + "?text1=" + text1.getText().toString()
			+ "&text2=" + text2.getText().toString();
			// 创建HttpGet对象
			HttpGet request = new HttpGet(url);
			// 创建HttpClient对象
			HttpClient client = new DefaultHttpClient();
			HttpResponse httpResponse = null;
			try {
				httpResponse = client.execute(request);
				if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				text3.setText(EntityUtils.toString(httpResponse.getEntity(),
				"utf-8"));
			}
			} catch (ClientProtocolException e) {
			e.printStackTrace();
			} catch (IOException e) {
			e.printStackTrace();
			
			}
		}
		
		public void post() {

			// 创建HttpPost对象

			HttpPost httpRequest = new HttpPost(httpUrl+"/user.json");

			// 创建传递参数集合

			List params = new ArrayList();

			params.add(new BasicNameValuePair("text1", text1.getText().toString()));
			params.add(new BasicNameValuePair("text2", text2.getText().toString()));

			// 设置字符集

			try {

			HttpEntity entity = new UrlEncodedFormEntity(params, "utf-8");

			httpRequest.setEntity(entity);

			// 创建连接对象

			HttpClient client = new DefaultHttpClient();

			// 执行连接

			HttpResponse response = client.execute(httpRequest);

			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

			text3.setText(EntityUtils.toString(response.getEntity(),

			"utf-8"));

			}

			} catch (UnsupportedEncodingException e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			} catch (ClientProtocolException e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			} catch (IOException e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			}
		
		}*/
}
